const mysql = require("mysql")

let pool = mysql.createPool({
    host: "127.0.0.1",
    user: "root",
    password: "root",
    port: 3306,
    database: "exam"
})
function getcon() {
    return new Promise((resolve, rejects) => {
        pool.getConnection((err, con) => {
            if (err) {
                rejects(err)
            } else {
                resolve(con)
            }
        })
    })
}
async function sql(sql, arr) {
    let con = await getcon();
    return new Promise((resolve, rejects) => {
        con.query(sql, arr, (err, data) => {
            if (err) {
                rejects(err)
            } else {
                resolve(data)
            }
        })
        con.release()
    })
}
module.exports = sql